<?php
class dashboard extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->model('m_config');
		$this->load->helper('terbilang');
	}
 
    function index(){
        $data = $this->m_config->_data();
        $html = $data->config_dashboard;
        $html = str_replace("{NO_ANTRIAN}","<span id=nomor_antrian></span>",$html);
        $html = str_replace("{LIST_ANTRIAN}","<table id=list_antrian></table>",$html);
        $data_html["html"] = $html;
        $this->load->view("app/v_dashboard",$data_html);
    }
    
    function antrian(){
        $id = $this->input->post('pengunjung_id');
        $antrian = $this->m_public_function->antrian($id);
        if ($antrian != "-"){
            $nomor = $antrian->pengunjung_nomor;
            $panggilke = $antrian->pengunjung_panggilanke;
            $seq = $antrian->pengunjung_seq;
            $loket_nomor = $antrian->pengunjung_loketnomor;
            
            $data = $this->m_config->_data();
            $suara = $data->config_suara;
            $suara = str_replace("{NO_ANTRIAN}",terbilang( $seq),$suara);
            $suara = str_replace("{NO_LOKET}",terbilang( $loket_nomor),$suara);
                
            $spel = $suara;//"nomor-urut ".terbilang( $seq)." loket ".terbilang( $loket_nomor);
        }else{
             $nomor= "-";
            $panggilke = 0;
            $spel = "";
        }
        $return  = array(
            "nomor" => $nomor,
            "panggilke" =>  $panggilke,
            "spel" =>  $spel,
            "list" => $this->m_public_function->all_antrian(),
            "md5" => md5(json_encode($this->m_public_function->all_antrian()))
        );
        echo json_encode($return);
    }
    
    function suara($text = ""){
        if ($text == ""){
            header("HTTP/1.0 404 Not Found");
        }else{
            $filename = $this->m_public_function->getfilename($text);
            $file = 'assets/audio/'.$filename;
    
           if(file_exists($file)){
                header('Content-type: {$mime_type}');
                header('Content-length: ' . filesize($file));
                header('Content-Disposition: filename="' . basename($filename));
                header('X-Pad: avoid browser bug');
                header('Cache-Control: no-cache');
                readfile($file);
            }else{
                header("HTTP/1.0 404 Not Found");
            }
        }
        
    }
}